package com.core.dao;

import java.util.Date;

import org.springframework.stereotype.Repository;

import com.core.base.dao.BaseHibernateDao;
import com.core.model.Project;

/**
 * project dao
 * 
 * @author pt-chenqw
 *
 */
@Repository("projectDAO")
public class ProjectDAO extends BaseHibernateDao<Project> {
	
	/**
	 * 查询最新一条数据的ID
	 * @return
	 */
	public Project getNewestProject(){
		String hql = "select max(id) from Project";
		int maxID = countByHql(hql).intValue();
		return getProjectByID(maxID);
	}
	
	/**
	 * 查询项目详情
	 * @param id
	 * @return
	 */
	public Project getProjectByID(Integer id){
		String hql = "from Project where id = ?";
		return findOne(hql, id);
	}
	
	/**
	 * 新增项目
	 * @param project
	 */
	public void addProject(Project project){
		project.setCreatetime(new Date());
		project.setUpdatetime(new Date());
		save(project);
	}
	
	/**
	 * 更新项目信息
	 * @param project
	 */
	public void updateProject(Project project){
		Project up = getProjectByID(project.getId());
		//更新具体的字段
		up.setUpdatetime(new Date());
		update(up);
	}
	
	/**
	 * 删除项目
	 * @param id
	 */
	public void deleteProject(Integer id){
		Project project = getProjectByID(id);
		delete(project);
	}

}
